package KVtext;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */

class Food {
}
class Fruit extends Food {
}
class Apple extends Fruit {
}
class Banana extends Fruit {
}
class Message1<T> { // 设置泛型
    private T message ;
    public T getMessage() {
        return message;
    }
    public void setMessage(T message) {
        this.message = message;
    }
}
public class Text1 {
    public static void main(String[] args) {
        Message<Banana> message1 =new Message<>();
        Message<Fruit> message2 =new Message<>();
        Message<Food> message3 =new Message<>();
        func1(message2);
        func1(message3);
        func1(message1);
    }
    public static void func1(Message<? super Fruit> message){
        message.setMessage(new Fruit());
        message.setMessage(new Banana());
        message.setMessage(new Food());
        message.setMessage((Fruit) new Food());
        Banana banana=(Banana) message.getMessage();
    }

    public static void main1(String[] args) {
        Message<Banana> message1 =new Message<>();
        Message<Fruit> message2 =new Message<>();
        Message<Food> message3 =new Message<>();
        func(message1);
        func(message2);
//        func(message3);
    }
    public static void func(Message<? extends Fruit> message){
        Fruit fruit =message.getMessage();
//        message.setMessage(new Banana());
//        message.setMessage(new Fruit());
//        message.setMessage(new Food());
    }
}
